import type { PageData } from '#/axios'
import request from '@/utils/request'

export interface Merchant {
  mrchId: number
  mid: string
  name: string
  shortName: string
  mrchNo: number | null
  businessLicense: string | null
  contactName: string
  mobile: string
  email: string
  countryCode: string
  areaCode: string | null
  provName: string | null
  cityName: string | null
  areaName: string | null
  postCode: string
  address: string
  creTime: number | number
  updTime: number | null
  status: number
  remark: string | null
  characterCode: string | null
  keyId: number | null
  keyName: string | null
  binderOrgId: number
  binderOrgName: string
  characterBindOuterEntityList: [] | null
  passId: number
  passName: string
}

interface MerhcantResponse extends PageData{
  data: Merchant[]
}

// 分页查询终端
export function getMerchantList(params) {
  return request({
    url: '/online/flypass/merchants',
    method: 'get',
    params
  })
}

export function getMerchantPage(params):Promise<MerhcantResponse> {
  return request({
    url: '/online/flypass/merchants',
    method: 'get',
    params
  })
}

export function addMerchant(data) {
  return request({
    url: `/online/authorization/operator/merchant`,
    method: 'POST',
    data
  })
}

export function configMerchantDevice(merchantId) {
  return request({
    url: `/online/flypass/merchant/${merchantId}/device-config`,
    method: 'POST'
  })
}

export function getMerchant(merchantId) {
  return request({
    url: `/online/flypass/merchant/${merchantId}`,
    method: 'get'
  })
}

export function updateMerchant(merchantId, data) {
  return request({
    url: `/online/flypass/merchant/${merchantId}`,
    method: 'PUT',
    data
  })
}

export function lockMerchant(merchantId) {
  return request({
    url: `/online/authorization/operator/merchant/${merchantId}/lock`,
    method: 'post'
  })
}

export function unlockMerchant(merchantId) {
  return request({
    url: `/online/authorization/operator/merchant/${merchantId}/unlock`,
    method: 'post'
  })
}
export function deleteMerchant(merchantId) {
  return request({
    url: `/online/flypass/merchant/${merchantId}`,
    method: 'DELETE'
  })
}

/**
 * 新绑定外部商户
 * @param {number} merchantId
 * @param {object} data id channel outerMrchNo outerMrchName
 * @returns
 */
export function newLinkOuterMerchant(merchantId, data) {
  return request({
    url: `/online/flypass/merchant/${merchantId}/external`,
    method: 'POST',
    data
  })
}

export function getLinkOuterMerchant(merchantId, data) {
  return request({
    url: `/online/flypass/merchant/${merchantId}/external`,
    method: 'GET',
    data
  })
}

/**
 * 更新商户关联外部平台信息
 * @param {*} merchantId
 * @param {object} data id channel outerMrchNo outerMrchName
 * @returns
 */
export function updateLinkOuterMerchant(merchantId, data) {
  return request({
    url: `/online/flypass/merchant/${merchantId}/external`,
    method: 'PUT',
    data
  })
}
/**
 * 删除商户关联的外部平台信息
 * @param {*} data {ids:[]}
 * @returns
 */
export function deleteLinkOuterMerchant(data) {
  return request({
    url: `/online/flypass/merchant/external`,
    method: 'DELETE',
    data
  })
}

export function getStaticUrl(merchantId) {
  return request({
    url: `/online/flypass/merchant/${merchantId}/pass/static-url`,
    method: 'GET'
  })
}

export function genStaticUrl(merchantId) {
  return request({
    url: `/online/flypass/merchant/${merchantId}/pass/static-url`,
    method: 'POST'
  })
}

//获取商户数量
export function getMrchNum() {
  return request({
    url: `/online/flypass/dashboard/merchant/count`,
    method: 'get'
  })
}
